package com.yalantis.beamazingtoday.ui.callback;

import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewPropertyAnimatorCompat;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.view.View;

import com.yalantis.beamazingtoday.Constant;
import com.yalantis.beamazingtoday.R;
import com.yalantis.beamazingtoday.interfaces.AnimationType;
import com.yalantis.beamazingtoday.listeners.BatListener;

/**
 * Created by galata on 18.07.16.
 */
public class BatCallback extends ItemTouchHelper.SimpleCallback {

    private BatListener mListener;

    public BatCallback(BatListener listener) {
        super(ItemTouchHelper.UP | ItemTouchHelper.DOWN, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT);
        mListener = listener;
    }

    @Override
    public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
        if (mListener != null) {
            mListener.move(viewHolder.getAdapterPosition(), target.getAdapterPosition());
        }
        if (viewHolder != null) {
            final View view = viewHolder.itemView;
            ViewCompat.animate(view).scaleX(1f).scaleY(1f)
                    .setDuration(200);
        }
        return false;
    }

    @Override
    public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
        if (mListener != null) {
            mListener.delete(viewHolder.getAdapterPosition());
        }
    }

    @Override
    public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
        super.onSelectedChanged(viewHolder, actionState);
        if (viewHolder != null && actionState == ItemTouchHelper.ACTION_STATE_DRAG) {
            final View view = viewHolder.itemView;
            ViewCompat.animate(view).scaleX(1.05f).scaleY(1.05f)
                    .setDuration(200);
        }
    }
}
